package cn.colat.micse.common.exception;


import cn.colat.micse.common.code.ResCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author 张曦
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class GlobalServerException extends RuntimeException {
    /**
     * 异常编码
     */
    private final int code;
    /**
     * 错误码字符
     */
    private final String codeText;
    /**
     * 异常消息
     */
    private final String message;

    public GlobalServerException(String message) {
        super(message);
        this.code = ResCode.REQUEST_ERROR.getCode();
        this.codeText = ResCode.REQUEST_ERROR.getCodeText();
        this.message = message;
    }

    public GlobalServerException(int code, String message) {
        super(message);
        this.code = code;
        this.codeText = ResCode.REQUEST_ERROR.getCodeText();
        this.message = message;
    }

    public GlobalServerException(int code, String codeText, String message) {
        super(message);
        this.code = code;
        this.codeText = codeText;
        this.message = message;
    }

    public GlobalServerException(ResCode code) {
        super(code.getMessage());
        this.code = code.getCode();
        this.codeText = code.getCodeText();
        this.message = code.getMessage();
    }
}

